/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package logica;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author andresgodoysalavert
 */
public class Apuesta {

    private int id;
    private int monto;
    private Date fecha;
    private Date hora;
    private int maquina_id;
    Evento evento = new Evento();
    Participante participante = new Participante();
    private Connection conexion;


    public void insertarApuesta(int idEv, int idPar, int monto, int pos){
        try {
            ConexionBD c = new ConexionBD();
            conexion = c.conectarBD();
            String query = "";
            PreparedStatement ps;
           
            if(pos==1){
                query = "INSERT INTO apuestas VALUES(null,"+monto+",current_date,current_time,1,null,null,0)";
                ps = conexion.prepareStatement(query);
                ps.executeUpdate();
            }
            query = "SELECT MAX(id) FROM apuestas";
            ps = conexion.prepareStatement(query);
            ResultSet rs = ps.executeQuery();
            int idAp = rs.getInt(1);
            query = "INSERT INTO participante_evento_apuestas VALUES(null,"+idPar+","+idEv+","+idAp+",null,null,"+pos+")";
            ps = conexion.prepareStatement(query);
            ps.executeUpdate();
            conexion.close();
        } catch (SQLException ex) {
            Logger.getLogger(Apuesta.class.getName()).log(Level.SEVERE, null, ex);
        }
    }


    public String getApuesta() throws SQLException{
            ConexionBD c = new ConexionBD();
            conexion = c.conectarBD();

            String query = "SELECT MAX(id) FROM apuestas";
            PreparedStatement ps = conexion.prepareStatement(query);
            ResultSet rs = ps.executeQuery();
            int idAp = rs.getInt(1);
            query = "SELECT * FROM apuestas WHERE id="+idAp;
            ps = conexion.prepareStatement(query);
            rs = ps.executeQuery();
            String factura = "Apuesta realizada en la Fecha: "+rs.getString(3)+" a la Hora: "+rs.getString(4)+"\n MONTO: "+rs.getString(2);
            conexion.close();
            return factura;

    }
    




    /**
     * @return the id
     */
    public int getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(int id) {
        this.id = id;
    }

    /**
     * @return the monto
     */
    public int getMonto() {
        return monto;
    }

    /**
     * @param monto the monto to set
     */
    public void setMonto(int monto) {
        this.monto = monto;
    }

    /**
     * @return the fecha
     */
    public Date getFecha() {
        return fecha;
    }

    /**
     * @param fecha the fecha to set
     */
    public void setFecha(Date fecha) {
        this.fecha = fecha;
    }

    /**
     * @return the hora
     */
    public Date getHora() {
        return hora;
    }

    /**
     * @param hora the hora to set
     */
    public void setHora(Date hora) {
        this.hora = hora;
    }

    /**
     * @return the maquina_id
     */
    public int getMaquina_id() {
        return maquina_id;
    }

    /**
     * @param maquina_id the maquina_id to set
     */
    public void setMaquina_id(int maquina_id) {
        this.maquina_id = maquina_id;
    }
    

}
